package com.openvas.controller;

import java.util.List;
//    import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.openvas.commons.common.annotation.Log;
import com.openvas.commons.common.enums.BusinessType;
import com.openvas.domain.TableSchedule;
import com.openvas.service.ITableScheduleService;
import com.openvas.commons.common.core.controller.BaseController;
import com.openvas.commons.common.core.domain.AjaxResult;

import com.openvas.commons.common.core.page.TableDataInfo;

/**
 * 定时Controller
 * 
 * @author ruoyi
 * @date 2021-11-04
 */
@Controller
@RequestMapping("/api/schedule")
public class TableScheduleController extends BaseController
{
    private String prefix = "system/schedule";

    @Autowired
    private ITableScheduleService tableScheduleService;

   // //  @RequiresPermissions("system:schedule:view")
    @GetMapping()
    public String schedule()
    {
        return prefix + "/schedule";
    }

    /**
     * 查询定时列表
     */
   // //  @RequiresPermissions("system:schedule:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TableSchedule tableSchedule)
    {
        startPage();
        List<TableSchedule> list = tableScheduleService.selectTableScheduleList(tableSchedule);
        return getDataTable(list);
    }

    /**
     * 导出定时列表
     */
   // //  @RequiresPermissions("system:schedule:export")
    @Log(title = "定时", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TableSchedule tableSchedule)
    {
        List<TableSchedule> list = tableScheduleService.selectTableScheduleList(tableSchedule);
//        ExcelUtil<TableSchedule> util = new ExcelUtil<TableSchedule>(TableSchedule.class);
//        return util.exportExcel(list, "定时数据");
        return null;
    }

    /**
     * 新增定时
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存定时
     */
   // //  @RequiresPermissions("system:schedule:add")
    @Log(title = "定时", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TableSchedule tableSchedule)
    {
        return toAjax(tableScheduleService.insertTableSchedule(tableSchedule));
    }

    /**
     * 修改定时
     */
    @GetMapping("/edit/{scheduleId}")
    public String edit(@PathVariable("scheduleId") String scheduleId, ModelMap mmap)
    {
        TableSchedule tableSchedule = tableScheduleService.selectTableScheduleByScheduleId(scheduleId);
        mmap.put("tableSchedule", tableSchedule);
        return prefix + "/edit";
    }

    /**
     * 修改保存定时
     */
   // //  @RequiresPermissions("system:schedule:edit")
    @Log(title = "定时", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TableSchedule tableSchedule)
    {
        return toAjax(tableScheduleService.updateTableSchedule(tableSchedule));
    }

    /**
     * 删除定时
     */
   // //  @RequiresPermissions("system:schedule:remove")
    @Log(title = "定时", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tableScheduleService.deleteTableScheduleByScheduleIds(ids));
    }
}
